package tools;

import entities.BigEnemy;
import entities.FlyingObject;
import entities.HeroPlane;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.IOException;

public class Explosion{
    /*
    包含成员变量：x，y，图片
 */

    public static BufferedImage[] big_Enemy, little_Enemy, hero;
    private int x;
    private int y;
    private BufferedImage imageNow = null;
    private BufferedImage[] bufferedImages = null;
    private int count = 0;
    //加载所有爆炸图片
    static {
        big_Enemy = new BufferedImage[4];
        little_Enemy = new BufferedImage[4];
        hero = new BufferedImage[4];

        try {
            //加载所有爆炸图片
            big_Enemy[0] = ImageIO.read(index.StartGame.class.getResourceAsStream("../pic/bigplane_ember0.png"));
            big_Enemy[1] = ImageIO.read(index.StartGame.class.getResourceAsStream("../pic/bigplane_ember1.png"));
            big_Enemy[2] = ImageIO.read(index.StartGame.class.getResourceAsStream("../pic/bigplane_ember2.png"));
            big_Enemy[3] = ImageIO.read(index.StartGame.class.getResourceAsStream("../pic/bigplane_ember3.png"));
            little_Enemy[0] = ImageIO.read(index.StartGame.class.getResourceAsStream("../pic/airplane_ember0.png"));
            little_Enemy[1] = ImageIO.read(index.StartGame.class.getResourceAsStream("../pic/airplane_ember1.png"));
            little_Enemy[2] = ImageIO.read(index.StartGame.class.getResourceAsStream("../pic/airplane_ember2.png"));
            little_Enemy[3] = ImageIO.read(index.StartGame.class.getResourceAsStream("../pic/airplane_ember3.png"));
            hero[0] = ImageIO.read(index.StartGame.class.getResourceAsStream("../pic/hero_ember0.png"));
            hero[1] = ImageIO.read(index.StartGame.class.getResourceAsStream("../pic/hero_ember1.png"));
            hero[2] = ImageIO.read(index.StartGame.class.getResourceAsStream("../pic/hero_ember2.png"));
            hero[3] = ImageIO.read(index.StartGame.class.getResourceAsStream("../pic/hero_ember3.png"));
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    public Explosion() {
    }

    public Explosion(int x, int y, FlyingObject flyingObject) {
        this.x = x;
        this.y = y;
        if (flyingObject instanceof HeroPlane){
            this.bufferedImages = hero;
        } else if (flyingObject instanceof BigEnemy) {
            this.bufferedImages = big_Enemy;
        } else/* if (flyingObject instanceof LittleEnemy) */{
            this.bufferedImages = little_Enemy;
        }
        this.bufferedImages = bufferedImages;

        this.imageNow = bufferedImages[0];
    }

    public void changeImg() {
        //移动就变成图片切换
        count++;
        imageNow = bufferedImages[count % bufferedImages.length];
        if (count == bufferedImages.length){
            count = -1;
        }
    }

    public BufferedImage[] getBufferedImages() {
        return bufferedImages;
    }

    public void setBufferedImages(BufferedImage[] bufferedImages) {
        this.bufferedImages = bufferedImages;
    }

    public int getX() {
        return x;
    }

    public void setX(int x) {
        this.x = x;
    }

    public int getY() {
        return y;
    }

    public void setY(int y) {
        this.y = y;
    }

    public int getCount() {
        return count;
    }

    public void setCount(int count) {
        this.count = count;
    }

    public BufferedImage getImageNow() {
        return imageNow;
    }

    public void setImageNow(BufferedImage imageNow) {
        this.imageNow = imageNow;
    }
}
